package com.webcode.utils;

import java.sql.Connection;
import java.sql.SQLException;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * @ClassName JdbcUtils.java
 * @Description TODO
 * @Author wushaopei
 * @Date 2020年9月19日
 * @Version 1.0
 */
public class JdbcUtils {
	
	static ComboPooledDataSource dataSource = new ComboPooledDataSource("book_devoloper");
	
	/**
	 * 获取数据库连接
	 * 
	 * @return
	 */
	public static Connection getConnection() {
		Connection connection = null;
		
		try {
			connection = dataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return connection;
	}

	/**
	 * 释放连接
	 */
	public static void closeConnection(Connection connection) {
		if (connection != null) {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
